package com.itheima.xx.test01;

import com.itheima.xx.dao.UserMapper;
import com.itheima.xx.pojo.User;
import com.itheima.xx.util.SqlSessionUtil1;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 *
 * @author codermao
 * @date 2023/10/26 11:28
 */
public class UserMapperTest01 {
    @Test
    public void test01() {
        SqlSession session = SqlSessionUtil1.getSession();
        UserMapper userMapper = session.getMapper(UserMapper.class);

        List<User> users = userMapper.queryUsersBySexOrUserName("三");

        for (User user : users) {
            System.out.println(user);
        }

        session.close();
    }

    @Test
    public void test02() {
        SqlSession session = SqlSessionUtil1.getSession();
        UserMapper userMapper = session.getMapper(UserMapper.class);
        List<User> users = userMapper.queryUsersBySexOrUserNameOrAddr("", "");

        for (User user : users) {
            System.out.println(user);
        }

        session.close();
    }

    @Test
    public void test03() {
        SqlSession session = SqlSessionUtil1.getSession();
        UserMapper userMapper = session.getMapper(UserMapper.class);
        List<User> users = userMapper.queryUsersByUserNameAndAddress("", "");

        for (User user : users) {
            System.out.println(user);
        }

        session.close();
    }

    @Test
    public void test04() {
        SqlSession session = SqlSessionUtil1.getSession();
        UserMapper userMapper = session.getMapper(UserMapper.class);
        User user = new User(9, "李莲花", new Date(89, 6, 6), "男", null);
        userMapper.updateUserById(user);

        session.close();
    }

    @Test
    public void test05() {
        SqlSession session = SqlSessionUtil1.getSession();
        UserMapper userMapper = session.getMapper(UserMapper.class);
        List<Integer> listIds = new ArrayList<>();
        listIds.add(1);
        listIds.add(2);
        listIds.add(9);
        List<User> users = userMapper.queryUsersByIds(listIds);
        for (User user : users) {
            System.out.println(user);
        }

        session.close();
    }
}
